package com.ce.pms.renovation.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.service.ISysrefcodeService;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.model.HouseDomain;
import com.ce.pms.house.service.IBuildingService;
import com.ce.pms.house.service.IHouseService;
import com.ce.pms.house.vo.BuildingVO;
import com.ce.pms.renovation.service.ICertificateManageService;
import com.ce.pms.renovation.service.ICheckConfirmService;
import com.ce.pms.renovation.service.IFlowManageService;
import com.ce.pms.renovation.service.IInspectionService;
import com.ce.pms.renovation.service.IRenovateChargeService;
import com.ce.pms.renovation.service.IRenovateManageService;
import com.ce.pms.renovation.vo.ApprovalItemVO;
import com.ce.pms.renovation.vo.CheckConfirmItemVO;
import com.ce.pms.renovation.vo.RenovateApprovalVO;
import com.ce.pms.renovation.vo.RenovateChargeItemVO;
import com.ce.pms.renovation.vo.RenovateLicenceVO;
import com.ce.pms.renovation.vo.RenovateRequisitionQueryVO;
import com.ce.pms.renovation.vo.RenovateRequisitionVO;
import com.ce.util.BlankUtil;
import com.ce.util.DateUtil;
import com.sitechasia.webx.components.xtable.util.ExtremeUtils;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.annotation.Scope;
import com.sitechasia.webx.core.support.Page;

/**
 * 装修申办 Action
 * @author 黄彦军
 *
 */
public class RenovateRequisitionAction extends PmsBaseAction {

	private IBuildingService buildingService;

	private ISysrefcodeService sysrefcodeService;

	private IRenovateManageService renovateManageService;

	private IRenovateChargeService renovateChargeService;

	private ICheckConfirmService checkConfirmService;

	private ICertificateManageService certificateManageService;

	private IFlowManageService flowManageService;

	private IHouseService houseService;

	private IInspectionService inspectionService;

	/**
	 * 功能描述:导航到装修申请列表页面 (首次加载，空列表) <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-22  <br>
	 */
	public String navigateEmptyRenovateRequisitionList(){
		setAttribute("totalRows", new Integer(0));
		return "renovateRequisitionList";
	}

	/**
	 * 功能描述:装修申请单查询  <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-22  <br>
	 */
	public String queryRequisitions(
			@Read(key = "ec_crd",defaultValue="15")	int pageSize,
            @Read(key = "ec_p", defaultValue="1")	int pageNo){

		RenovateRequisitionQueryVO queryVO = getRenReqSearchCondition();
		queryVO.setSortStr(ExtremeUtils.getOrderString(this.getRequest()));
		queryVO.setPageNo(pageNo);
		queryVO.setPageSize(pageSize);
		Page page = renovateManageService.queryRequisitions(queryVO);
		Long totalRows = page.getTotalCount();
		List<RenovateRequisitionVO> reqlist = page.getResult();

		setAttribute("totalRows",totalRows.intValue());
		setAttribute("reqlist", reqlist);
		setAttribute("ec_p", pageNo);

		return "renovateRequisitionList";
	}

	/**
	 * 功能描述:设置装修申办查询条件 <br>
	 * @param queryVO
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public void setRenReqSearchCondition(@Read RenovateRequisitionQueryVO queryVO){
		setAttribute("renReqSearchCondition", queryVO,Scope.SESSION);
	}

	/**
	 * 功能描述:获取装修申办查询条件  <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public RenovateRequisitionQueryVO getRenReqSearchCondition(){
		RenovateRequisitionQueryVO queryVO = (RenovateRequisitionQueryVO) getAttribute("renReqSearchCondition");
		return queryVO == null ? new RenovateRequisitionQueryVO() : queryVO ;

	}

	public void setInspectionService(IInspectionService inspectionService) {
		this.inspectionService = inspectionService;
	}

	/**
	 * 功能描述:导航到 装修申办高级查询页面   <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-22  <br>
	 */
	public String navigateRenRequisitionSearch(){

		setBuildingList();//楼栋
		setLicenceStates(); //许可证状态
		setChargeStates();//费用状态
		setRequisitionStates();//审批状态

		return "renovateRequisitionSearch";
	}

	/**
	 * 功能描述:导航到新增装修申请页面  <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public String navigateAddRequisition(){
		setLevels();
		return "requisitionAdd";
	}

	/**
	 * 功能描述:验证房号是否符合新增要求  <br>
	 * @param houseNumber
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public void checkHouseNumber(@Read (key="houseNumber") String houseNumber){
		try {
			renovateManageService.isAllowAddRequisition(houseNumber);
			this.renderText("true");
		} catch (BusinessException e) {
			this.renderText(super.getLocaleMessage(e.getMessage()));
		}
	}

	/**
	 * 功能描述:返回指定房间的业主姓名及房屋面积  <br>
	 * @param houseNumber
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public void getHouseInfo(@Read (key="houseNumber") String houseNumber){
		HouseDomain houseDomain = houseService.getHouseByNumber(houseNumber);
		String owner = houseService.getOwnerNameBy(houseNumber);
		this.renderText("{'clientNames':'"+owner+"','area':'"+houseDomain.getBuildSize()+"'}");
	}

	/**
	 * 功能描述:新增装修申请<br>
	 * @param requisitionVO
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public void addRequisition(@Read RenovateRequisitionVO requisitionVO){
		requisitionVO.setCreator(this.getUserId());
		RenovateRequisitionVO renovateRequisitionVO =renovateManageService.addRequisition(requisitionVO);

		setAttribute("renReqSearchCondition", null,Scope.SESSION);

		this.renderText(renovateRequisitionVO.getKeyword().toString());
	}

	/**
	 * 功能描述:检查是否可以进行修改  <br>
	 * @param keyword
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-24  <br>
	 */
	public void checkRequisitionEdit(@Read (key="keyword") Long requisitionId){
		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);
		if(SysrefcodeDO.RM_RENOVATE_REQUISITION_STATE_NEW.equals(requisitionVO.getRequisitionState())){
			this.renderText("true");
		}else{
			this.renderText("false");
		}

	}

	/**
	 * 功能描述:导航到修改装修申请页面   <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public String navigateEditRequisition(@Read (key="keyword") Long requisitionId){

		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);
		setAttribute("requisitionVO", requisitionVO);
		setLevels();

		return "requisitionEdit";
	}

	/**
	 * 功能描述:修改装修申请  <br>
	 * @param requisitionVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public void editRequisition(@Read RenovateRequisitionVO requisitionVO){

		renovateManageService.editRequisition(requisitionVO);
	}

	/**
	 * 功能描述:检查是否可以删除  <br>
	 * @param keyword
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-24  <br>
	 */
	public void checkDelete(@Read (key="keyword") Long requisitionId){
		try {
			Boolean flag= renovateManageService.isAllowDeleteRequisition(requisitionId);
			this.renderText(flag.toString());
		} catch (BusinessException e) {
			this.renderText(super.getLocaleMessage(e.getMessage()));
		}
	}

	/**
	 * 功能描述:删除装修申请 <br>
	 * @param keyword
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public String deleteRequisition(@Read (key="keyword") Long requisitionId){

		renovateManageService.deleteRequisition(requisitionId);

		setAttribute("iframeName", "refleshRenReqFrame");
		return "onlyRefresh";
	}

	/**
	 * 功能描述: 作废申请 <br>
	 * @param requisitionId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-5  <br>
	 */
	public String blankOutRequisition(@Read (key="keyword") Long requisitionId){

		renovateManageService.blankOutRequistion(requisitionId);

		setAttribute("iframeName", "refleshRenReqFrame");
		return "onlyRefresh";
	}

	/**
	 * 功能描述: 检查是否可能进行提交操作 <br>
	 * @param requisitionId
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-31  <br>
	 */
	public void checkSubmitPage(@Read (key="requisitionId")Long requisitionId){
		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);
		if(SysrefcodeDO.RM_RENOVATE_REQUISITION_STATE_NEW.equals(requisitionVO.getRequisitionState())){
			 this.renderText("true");
		}else{
			this.renderText("false");
		}
	}

	/**
	 * 功能描述:导航到提交页面  <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-31  <br>
	 */
	public String navigateSubmitPage(@Read (key="requisitionId")Long requisitionId){
		List firstList =  sysrefcodeService.querySysrefCodesByCode("RM_REN_REQ_FIRST_APP_EMPLOYEE");
		List secondList = sysrefcodeService.querySysrefCodesByCode("RM_REN_REQ_SECOND_APP_EMPLOYEE");

		SysrefcodeDO secondVO = null;
		if (!BlankUtil.isBlank(secondList)){
			secondVO = (SysrefcodeDO) secondList.get(0);
		}

		setAttribute("secondVO", secondVO);
		setAttribute("firstList", firstList);
		setAttribute("totalRows", firstList.size());
		setAttribute("requisitionId", requisitionId);

		return "submitPage";
	}

	/**
	 * 功能描述:提交  <br>
	 * @param requisitionId
	 * @param employeeIds
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-31  <br>
	 */
	public void sumbitInfo(@Read (key="requisitionId")Long requisitionId ,
							@Read (key="firstIds")String firstIds,
							@Read (key="secondId")String secondId){
		//	Set firstId =strToSet(firstIds);
		flowManageService.submitRenovateRequisition(requisitionId, getFristAppSet(), getSecondApp(), getUserId());
	}

	/**
	 * 功能描述:获取 1 级审批人  <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-7  <br>
	 */
	private Set<Long> getFristAppSet(){

		List firstList =  sysrefcodeService.querySysrefCodesByCode("RM_REN_REQ_FIRST_APP_EMPLOYEE");//获取1级审批人

		if (BlankUtil.isBlank(firstList)) {
			return null;
		}

		Set<Long> firstId =new HashSet<Long>();
		for (Object object : firstList) {
			SysrefcodeDO sysrefcodeDO = (SysrefcodeDO) object;
			firstId.add(Long.valueOf(sysrefcodeDO.getValue()));
		}

		return firstId;
	}

	/**
	 * 功能描述: 获取2级审批人id <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-7  <br>
	 */
	private Long getSecondApp(){
		List secondList = sysrefcodeService.querySysrefCodesByCode("RM_REN_REQ_SECOND_APP_EMPLOYEE");//获取2级审批人
		if (BlankUtil.isBlank(secondList)) return null;
		SysrefcodeDO sysrefcodeDO = (SysrefcodeDO) secondList.get(0);

		return Long.valueOf(sysrefcodeDO.getValue());
	}

	/**
	 * 功能描述:检查是否可以进行登记收费  <br>
	 * @param requisitionId
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-5  <br>
	 */
	public void checkReqCharge(@Read (key="requisitionId")Long requisitionId,@Read(key="licenceState")String licenceState){
		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);
		if (SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_EXP.equals(requisitionVO.getProcessState())){//异常完结
			if(SysrefcodeDO.RM_RENOVATE_REQUISITION_STATE_NPASS.equals(requisitionVO.getRequisitionState())){//异常完结，是审批不通过状态
				this.renderText("abnormityNopass");
			}else if (BlankUtil.isBlank(requisitionVO.getRequisitionState())){//异常完结，是空状态
				this.renderText("abnormityNull");
			}
		}else if (SysrefcodeDO.RM_RENOVATE_LICENCE_STATE_OK.equals(licenceState)){ //许可证已发，不能进行
			this.renderText("licence");
		}else{
			this.renderText("true");
		}
	}

	/**
	 * 功能描述:导航到收费登记页面   <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public String navigateRequisitionCharge(@Read (key="keyword")Long requisitionId){
		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);

		List<RenovateChargeItemVO> itemList =requisitionVO.getRenovateChargeItemList();

		setAttribute("itemList", itemList);
		setAttribute("requisitionVO", requisitionVO);
		setAttribute("totalRows",itemList.size());
		setAttribute("requisitionId", requisitionId);

		return "requisitionCharge";
	}

	/**
	 * 功能描述:收费登记  <br>
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public void editRenovateChargeItems(@Read (key="items") String params,@Read(key="requisitionId")Long requisitionId){

		String [] parAll = params.split("#!end!#");
		List<RenovateChargeItemVO> list = new ArrayList<RenovateChargeItemVO>();
		for (int i = 0; i < parAll.length; i++) {
			String temp = parAll[i].toString();
			String [] item = temp.split("#!!#");

			RenovateChargeItemVO itemVO = new RenovateChargeItemVO();
			itemVO.setKeyword(new Long(item[0]));	//主键
			itemVO.setFeeState(item[1].toString());	//状态

			if(item.length == 3){
				itemVO.setRemark(item[2].toString());	//备注
			}
			list.add(itemVO);
		}
		renovateChargeService.editRenovateChargeItems(requisitionId,list);
	}

	/**
	 * 功能描述:检查是否可以进行进场确认  <br>
	 * @param requisitionId
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void checkConfirm(@Read (key="requisitionId") Long requisitionId){
		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);
		if(!SysrefcodeDO.RM_RENOVATE_REQUISITION_STATE_PASS.equals(requisitionVO.getRequisitionState())){//申批通过
			this.renderText("noPass");
		}else if (SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_NOR.equals(requisitionVO.getProcessState()) ||
				SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_EXP.equals(requisitionVO.getProcessState())){ //已完结，不能进行
			this.renderText("finish");
		}else{
			this.renderText("true");
		}
	}

	/**
	 * 功能描述:导航到进场确认页面  <br>
	 * @param keyword
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public String navigateCheckConfirm(@Read (key="keyword") Long requisitionId){

		List<CheckConfirmItemVO> confirms =checkConfirmService.getAllCheckConfirmItemConfigs(requisitionId);

		setAttribute("confirms", confirms);
		setAttribute("requisitionId",requisitionId);

		return "checkConfirm";
	}

	/**
	 * 功能描述:进场确认  <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public void checkConfirmItems(@Read (key="par") String per,@Read(key="requisitionId")Long requisitionId){
			String [] parAll = per.split("#!end!#");
			List<CheckConfirmItemVO> list = new ArrayList<CheckConfirmItemVO>();
			for (int i = 0; i < parAll.length; i++) {
				String temp = parAll[i];
				String [] item = temp.split("#!!#");

				CheckConfirmItemVO itemVO = new CheckConfirmItemVO();
				itemVO.setItemConfigId(Long.valueOf(item[0]));
				if(!BlankUtil.isBlank(item[1])){
					itemVO.setKeyword( Long.valueOf(item[1]));
				}

				itemVO.setCheckYn(item[2]);

				if (item.length == 4){
					itemVO.setRemark(item[3]);
				}
				list.add(itemVO);
			}

			checkConfirmService.checkConfirmItems(requisitionId,list);
	}

	/**
	 * 功能描述:检查是否可以打开许可证发放页面   <br>
	 * @param keyword  装修申请 Id
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-25  <br>
	 */
	public void checkTransactLicence(@Read (key= "keyword")Long requisitionId){
		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);
		RenovateLicenceVO licenceVO = certificateManageService.getLicence(requisitionId);
		Long licence = null;
		if(!BlankUtil.isBlank(licenceVO)){
			licence = licenceVO.getKeyword();
		}

		if (SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_NOR.equals(requisitionVO.getProcessState()) ||
				SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_EXP.equals(requisitionVO.getProcessState())){//完结，不能进行许可证发放
			this.renderText("finish");
		}else if (!SysrefcodeDO.RM_RENOVATE_REQUISITION_STATE_PASS.equals(requisitionVO.getRequisitionState())){//审批不通过不能进行发放
			this.renderText("noPass");
		}else if (SysrefcodeDO.RM_FEE_STATE_NO.equals(requisitionVO.getFeeState())){ //未缴费，不能进行发证
			this.renderText("noFee");
		}else if(!BlankUtil.isBlank(inspectionService.getPassReinspectionByLicenceId(licence))){
			this.renderText("reinspectionPass");
		}else{
			this.renderText("true");
		}
	}

	/**
	 * 功能描述:导航到 许可证发放 页面  <br>
	 * @param keyword	申请Id
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public String navigateTransactLicence(@Read (key = "keyword")Long requisitionId){
		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);
		RenovateLicenceVO licenceVO = certificateManageService.getLicence(requisitionId);
		if (BlankUtil.isBlank(licenceVO)){
			licenceVO = new RenovateLicenceVO();
			licenceVO.setState(requisitionVO.getRenovateLicenceState());
			licenceVO.setBeginDate(requisitionVO.getBeginDate());
			licenceVO.setEndDate(requisitionVO.getEndDate());
		}
		setAttribute("licenceVO", licenceVO);
		setAttribute("requisitionVO", requisitionVO);

		String sysCurrentDate = getSysDate();//服务器当前时间
		setAttribute("sysCurrentDate",sysCurrentDate );
		setLicenceStates();//许可证状态
		setAttribute("transactor", getUsername());
		return "transactLicence";
	}

	/**
	 * 功能描述:许可证发办理  <br>
	 * @param licenceVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-23  <br>
	 */
	public void editTransactLicence( @Read RenovateLicenceVO licenceVO){
		licenceVO.setCreator(getUserId());
		licenceVO.setTransactorId(getUserId()); //设置经办人
		licenceVO =certificateManageService.transactLicence(licenceVO);
		this.renderText(licenceVO.getKeyword().toString());
	}

	/**
	 * 功能描述:检查是否可以进行审批操作  <br>
	 * @param requisitionId
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-26  <br>
	 */
	public void checkRenovateApproval(@Read (key = "keyword")Long requisitionId){

		try {
			flowManageService.isAllowSubmitRenovateApproval(requisitionId, getUserId());
			this.renderText("true");
		} catch (BusinessException e) {
			this.renderText(super.getLocaleMessage(e.getMessage()));
		}
	}

	/**
	 * 功能描述:导航到审批页面  <br>
	 * @param requisitionId
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-26  <br>
	 */
	public String navigateRenovateApproval(@Read(key="keyword")Long requisitionId){

		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);//获取申请基本信息

		List<RenovateApprovalVO> approvalList = getAppItems(requisitionId); //列表

		RenovateApprovalVO approvalVO =	flowManageService.getRenovateApproval(getUserId(), requisitionId);//指定人的装修审批信息

		List<ApprovalItemVO> itemList =getItems(requisitionId);

		setAttribute("approvalList", approvalList); //列表
		setAttribute("totalRows", approvalList.size());
		setAttribute("itemList",itemList);//资料
		setAttribute("requisitionVO", requisitionVO);//基本信息
		setAttribute("approvalVO", approvalVO);//审核信息

		return "renovateApproval";
	}

	/**
	 * 功能描述:审批  <br>
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-26  <br>
	 */
	public void addRenovateApproval(@Read RenovateApprovalVO approvalVO,
			@Read(key="itemStr")String itemStr){

		approvalVO.setApprovalId(getUserId());
		approvalVO.setCreator(getUserId());
		approvalVO.setApprovalItems(itemStrToMap(itemStr));

		if (SysrefcodeDO.RM_APPROVAL_LEVEL_ONE.equals(approvalVO.getApprovalLevel())){
			flowManageService.firstRenovateApproval(approvalVO);
		}else if(SysrefcodeDO.RM_APPROVAL_LEVEL_TWO.equals(approvalVO.getApprovalLevel())){
			flowManageService.secondRenovateApproval(approvalVO);
		}
	}

	/**
	 * 功能描述:导航到详细主页面（双击） <br>
	 * @param requisitionId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-26  <br>
	 */
	public String navigateProceduresDetailMain(@Read (key="requisitionId")Long requisitionId){

		setAttribute("requisitionId", requisitionId);
		return "proceduresDetailMain";
	}

	/**
	 * 功能描述:装修申请详细  <br>
	 * @param requisitionId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-26  <br>
	 */
	public String requisitionsDetail(@Read (key="requisitionId")Long requisitionId){
		RenovateRequisitionVO requisitionVO = renovateManageService.getRequisition(requisitionId);
		setAttribute("requisitionVO", requisitionVO);
		return "requisitionsDetail";
	}

	/**
	 * 功能描述:装修审核详细 <br>
	 * @param requisitionId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-26  <br>
	 */
	public String renovateApprovalDetail(@Read (key="requisitionId")Long requisitionId){
		List<RenovateApprovalVO> approvalList =getAppItems(requisitionId);

		setAttribute("approvalList", approvalList);
		setAttribute("totalRows", approvalList == null ? 0:approvalList.size());
		return "renovateApprovalDetail";
	}

	/**
	 * 功能描述:许可证发放详细 <br>
	 * @param requisitionId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-26  <br>
	 */
	public String transactLicenceDetail(@Read (key="requisitionId")Long requisitionId){
		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);//装修申请
		RenovateLicenceVO licenceVO = certificateManageService.getLicence(requisitionId);//许可证信息
		if (BlankUtil.isBlank(licenceVO)){
			licenceVO = new RenovateLicenceVO();
			licenceVO.setState(requisitionVO.getRenovateLicenceState());
			licenceVO.setBeginDate(requisitionVO.getBeginDate());
			licenceVO.setEndDate(requisitionVO.getEndDate());
		}
		List<CheckConfirmItemVO> confirmItemList =checkConfirmService.getAllCheckConfirmItemConfigs(requisitionId);

		setAttribute("requisitionVO",requisitionVO);
		setAttribute("licenceVO",licenceVO);
		setAttribute("confirmItemList",confirmItemList);
		setAttribute("totalRows",confirmItemList == null ? 0 : confirmItemList.size());

		return "transactLicenceDetail";
	}

	/**
	 * 功能描述:收费情况详细  <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-26  <br>
	 */
	public String requisitionChargeDetail(@Read (key="requisitionId")Long requisitionId){

		RenovateRequisitionVO requisitionVO=renovateManageService.getRequisition(requisitionId);
		List<RenovateChargeItemVO> chargeItemList =requisitionVO.getRenovateChargeItemList();

		setAttribute("chargeItemList", chargeItemList);
		setAttribute("totalRows",chargeItemList== null ? 0 : chargeItemList.size() );
		return "requisitionChargeDetail";
	}

	/**
	 * 功能描述:审批时将资料字符串转换为Map   <br>
	 * @param itemStr
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-5  <br>
	 */
	private Map<Long, ApprovalItemVO> itemStrToMap(String itemStr){
		Map<Long, ApprovalItemVO> map = new HashMap<Long, ApprovalItemVO>();
		if(BlankUtil.isBlank(itemStr))
			return null;

		String str[] = itemStr.split(":");

		for (int i = 0; i < str.length; i++) {

			String temp = str[i];
			ApprovalItemVO itemVO = new ApprovalItemVO();

			String[] items = temp.split(",");
			itemVO.setKeyword(Long.valueOf(items[0]));
			itemVO.setResult(items[1]);

			map.put(Long.valueOf(items[0]), itemVO);
		}
		return map;
	}

	/**
	 * 功能描述: 获取审批列表 <br>
	 * @param requisitionId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-5  <br>
	 */
	private List<RenovateApprovalVO> getAppItems(Long requisitionId){

		List<RenovateApprovalVO> approvals = flowManageService.getAllIsHandleRenovateApproval(requisitionId);// 装修审核列表

		List<RenovateApprovalVO> appItems = new ArrayList<RenovateApprovalVO>();

		for (RenovateApprovalVO approvalVO : approvals) {

			String approvalItemView = "";

			Map<Long, ApprovalItemVO> map = approvalVO.getApprovalItems();
			for (ApprovalItemVO item : map.values()) {
				if("001".equals(item.getResult())){
					approvalItemView += item.getItemName()+ "(√)；";
				}else if("002".equals(item.getResult())){
					approvalItemView += item.getItemName() + "(X)；";
				}else {
					approvalItemView += item.getItemName() + "；";
				}
			}
			if (approvalItemView.length()>0){
				approvalItemView = approvalItemView.substring(0,approvalItemView.length()-1);
			}
			approvalVO.setApprovalItemView(approvalItemView);
			appItems.add(approvalVO);
		}

		return appItems;
	}

	/**
	 * 功能描述:获取审批资料  <br>
	 * @param requisitionId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-5  <br>
	 */
	private List<ApprovalItemVO> getItems(Long requisitionId){

		RenovateApprovalVO approvalVO =	flowManageService.getRenovateApproval(getUserId(), requisitionId);//指定人的装修审批信息
		List<ApprovalItemVO> list = new ArrayList<ApprovalItemVO>();
		Map<Long, ApprovalItemVO> map = approvalVO.getApprovalItems();
		for (ApprovalItemVO item : map.values()) {
			list.add(item);
		}

		return list;
	}

	/**
	 * 功能描述: 获取服务器当前系统时间 2008-12-12 <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-25  <br>
	 */
	private String getSysDate(){

		return DateUtil.convertDateToStr(renovateManageService.getDate(), "yyyy-MM-dd")	;
	}

	/**
	 * 功能描述: 缓存许可证状态 <br>
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-25  <br>
	 */
	private void setLicenceStates(){
		List licenceStates =  sysrefcodeService.querySysrefCodesByCode("RM_RENOVATE_LICENCE_STATE");
		setAttribute("licenceStates",licenceStates );
	}

	/**
	 * 功能描述:  缓存费用状态 <br>
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-25  <br>
	 */
	private void setChargeStates(){
		List chargeStates =  sysrefcodeService.querySysrefCodesByCode("RM_RENOVATE_FEE_STATE");
		setAttribute("chargeStates",chargeStates );
	}

	/**
	 * 功能描述:  缓存申请审批状态 <br>
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-25  <br>
	 */
	private void setRequisitionStates(){
		List requisitionStates =  sysrefcodeService.querySysrefCodesByCode("RM_RENOVATE_REQUISITION_STATE");
		setAttribute("requisitionStates",requisitionStates );
	}

	/**
	 * 功能描述:缓存资质等级  <br>
	 *
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-4  <br>
	 */
	private void setLevels(){
		setAttribute("levels", sysrefcodeService.querySysrefCodesByCode("RM_COMPANY_LEVEL"));
	}

	/**
	 * 功能描述:  缓存楼栋列表 <br>
	 * Create author:黄彦军 <br>
	 * Create on:2008-12-25  <br>
	 */
	private void setBuildingList(){
		List<BuildingVO> buildingList = buildingService.getAllBuildingList();
		setAttribute("buildingList", buildingList);
	}

//	/**
//	 * 功能描述:将一级审批字符串转化为 Set   <br>
//	 * @param firstIds
//	 * @return
//	 * Create author:黄彦军 <br>
//	 * Create on:2008-12-31  <br>
//	 */
//	private Set strToSet(String firstIds){
//		Set firstId = new HashSet();
//		String [] temp = firstIds.split(",");
//		if (temp.length ==0){
//			return null;
//		}
//		for (int i = 0; i < temp.length; i++) {
//			Long id = new Long(temp[i]);
//			firstId.add(id);
//		}
//
//		return firstId;
//	}

/***************************************************************************************/

	public void setBuildingService(IBuildingService buildingService) {
		this.buildingService = buildingService;
	}

	public void setSysrefcodeService(ISysrefcodeService sysrefcodeService) {
		this.sysrefcodeService = sysrefcodeService;
	}

	public void setRenovateManageService(
			IRenovateManageService renovateManageService) {
		this.renovateManageService = renovateManageService;
	}

	public void setRenovateChargeService(
			IRenovateChargeService renovateChargeService) {
		this.renovateChargeService = renovateChargeService;
	}

	public void setCheckConfirmService(ICheckConfirmService checkConfirmService) {
		this.checkConfirmService = checkConfirmService;
	}

	public void setCertificateManageService(
			ICertificateManageService certificateManageService) {
		this.certificateManageService = certificateManageService;
	}

	public void setFlowManageService(IFlowManageService flowManageService) {
		this.flowManageService = flowManageService;
	}

	public void setHouseService(IHouseService houseService) {
		this.houseService = houseService;
	}






}
